<?php

namespace App\Miya\Middlewares;

use Closure;

class SensitiveWordRemind
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (config('miya.sensitive_word_remind')) {
            $response = $next($request);
            $content = $response->content();

            $insertContentTpl = <<<Tmp
<style>
    .sensitive_word_remind{
        background: #0b0b0b;
        color: #fff;
        padding: 30px 200px;
        line-height: 20px;
       }
</style>
<div class="sensitive_word_remind">
%s
</div>
</body>
Tmp;

            $insertContent = sprintf($insertContentTpl, config('miya.sensitive_word_ps'));
            $content = str_replace(
                '</body>',
                $insertContent,
                $content
            );
            $response->setContent($content);
            return $response;
        } else {
            return $next($request);
        }
    }
}
